<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<script>
function CQGraph(heading, unit, itemUnit, data, alerts, itemAlertThreshold) {
  this.heading = heading;
  this.unit = unit;
  this.itemUnit = itemUnit;
  this.data = data;
  this.alerts = alerts || {};
  this.itemAlertThreshold =
      itemAlertThreshold !== undefined ? itemAlertThreshold : Infinity;
}

CQGraph.prototype.breachedItems = function(col, threshold) {
  return this.data.get().then(function(data) {
    var colIndex = data.cols.indexOf(col);
    var items = [];
    data.rows.forEach(function(row, i) {
      if (row[colIndex] >= threshold) {
        items.push({
          timestamp: row[0],
          value: row[colIndex],
          index: i,
        });
      }
    });
    return items;
  });
};
</script>
